<template>
	<view>
		<u-mask :show="showModal" @click="hideModal"></u-mask>
		<view class="container" v-show="showModal">
			<!--<view style="height: 35px;line-height: 35px;font-weight: bold;text-align: center;background-color: #b7d0f9;">选择成员</view>-->

			<view>
				<u-input border v-model="inputStr" placeholder="请输入疾病名称" />
			</view>

			<view class="loading" v-if="loading">
				<u-loading :size="60" :show="true" />
				<text class="txt">加载中</text>
			</view>
			<view v-show="!loading" class="staff-list">

				<view class="dis-container">
					<view class="tag"
						  v-for="(item,index) in diseaseList" :key="index"
						  :class="{'tag-selected':item.selected}"
						  @click="changeTagStatus(item,index)">{{item.name}}</view>
					<view class="tag" v-if="inputStr && diseaseList.length>0" @click="searchDiseaseList('more')">更多+</view>
				</view>

				<view v-if="inputStr && diseaseList.length==0" class="null">
					暂时无法匹配到相关疾病，请您尝试输入其他关键字
				</view>

			</view>

			<view style="height: 50px;"></view>
			<view class="btn-container">
				<view class="submit-btn" @click="submitBtn">确定</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default{
		props: {
			showModal: '',
			type: '',
			detail_id: ''
		},
		data() {
			return{
				diseaseList: [],
				loading: false,
				inputStr: '',
				page: 1,
				selectedList: []
			}
		},
		watch: {
			inputStr(val){
				if(val){
					this.page = 1
					this.searchDiseaseList()
				}
			},
			showModal(val){
				if(val){
					this.inputStr = ''
					this.diseaseList = []
					this.selectedList = []
				}
			}
		},
		methods: {
			hideModal(){
				this.$emit('hideChooseModal',false)
			},

			async searchDiseaseList(type) {
				if(type === 'more'){
					this.page = this.page + 1
				}
				const res = await this.$api.searchDiseaseList({
					disease_name: this.inputStr,
					limit: 15,
					page: this.page
				}, this.$baseUrl)
				if (res.data.level === "success") {
					if(type==='more'){
						if(res.data.data.length==0){
							this.$currency.showToast('没有更多了')
							return
						}
						res.data.data.forEach(item => {
							item.selected = false
						})
						this.diseaseList = this.diseaseList.concat(res.data.data)
					} else{
						this.diseaseList = res.data.data
						this.diseaseList.forEach(item => {
							item.selected = false
						})
					}
				}
			},

			changeTagStatus(item,index){
				item.selected = !item.selected
				this.$set(this.diseaseList,index,item)
				if(item.selected){
					this.selectedList.push(item)
				} else {
					let i = this.selectedList.indexOf(item)
					if(i != -1) {
						this.selectedList.splice(i,1)
					}
				}
			},

			submitBtn() {
				this.$emit('getMoreTag',this.selectedList)
				this.hideModal()
			},

		}
	}
</script>

<style lang="scss" scoped>
	.container{
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100vw;
		height: 70vh;
		z-index: 9999999;
		background-color: #FFFFFF;
		padding: 20rpx 20rpx 0 20rpx;
		box-sizing: border-box;
		.loading{
			padding: 20rpx 0;
			display: flex;
			justify-content: center;
			flex-direction: column;
			align-items: center;
			.txt{
				margin-top: 20rpx;
				color: grey;
			}
		}

	}

	.dis-container{
		display: flex;
		flex-wrap: wrap;
		margin-top: 16rpx;
		.tag{
			display: inline-block;
			align-items: center;
			-moz-box-align: center;
			box-sizing: border-box;
			line-height: 1;
			border-radius: 100rpx;
			font-size: 22rpx;
			padding: 15rpx 25rpx;
			background-color: #EDEDED;
			color: grey;
			margin-right: 20rpx;
			margin-bottom: 14rpx;
		}
		.tag-selected{
			color: #ffffff;
			background-color: #09C15F;
		}
	}

	.staff-list {
		width: 100vw;
		height: calc(70vh - 100px);
		overflow: auto;
		.staff-item:first-child{
			border-bottom: none;
			padding-top: 10rpx !important;
			padding-bottom: 0 !important;
		}
		.staff-item{
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 25rpx 20rpx;
			border-bottom: 1px solid #EDEDED;
			.item-left{
				display: flex;
				align-items: center;
				text-align: center;
				.head-icon{
					margin-left: 20rpx;
				}
				.nickname{
					margin: 0 20rpx;
				}
			}

			.item-right{

			}

		}

	}

	.btn-container{
		width: 100vw;
		height: 50px;
		position: fixed;
		bottom: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #FFFFFF;
	}
	.submit-btn{
		width: 204px;
		height: 40px;
		line-height: 40px;
		border-radius: 25px;
		background-color: #09C15F;
		color: #FFFFFF;
		text-align: center;
	}

</style>
